#ifndef ENTRY_H
#define ENTRY_H

#include "DomORM.h"
#include "Tag.h"

class TFile;
class TDir;
class Entry;

class RecordItem : public SharedDomObject
{
public:
    RecordItem(QDomElement source);
    RecordItem(TFile file);
    RecordItem(TDir dir);
    bool isDir();
    bool isFile();
    bool isVaild(); // dir  file
    TDir toDir();
    TFile toFile();

    QString name();
    void setName(const QString &name);

    static QString tagName() { return "dir_or_file"; }
};

typedef ElementList<RecordItem> RecordList;

class TFile : public SharedDomObject
{
    friend class RecordItem;
public:
    TFile(QDomElement source);

    QString name();
    quint64 size();
    QString qs();
    int relationId();

    void setSize(quint64 size);
    void setQs(const QString &qs);
    void setRelationId(int id);
    void setName(const QString &name);

    SimpleTagList simpleTags();

    static QString tagName() { return "file"; }

};

class TDir : public RecordList
{
    friend class RecordItem;
public:
    TDir(QDomElement source);
    TFile createNewFile(bool appendToList = true);
    TDir createNewDir(bool appendToList = true);
    RecordItem findChildByName(const QString &name);

    QString name();
    void setName(const QString &name);
    int relationId();
    void setRelationId(int id);

    static QString tagName() { return "dir"; }

// hide
private:
    RecordItem createNewChild(bool appendToList = true);
};

class Entry : public TDir
{
public:
    Entry(QDomElement source);
    static QString tagName() { return "entry"; }

    TFile createNewFile(const QString &filePath);
    TDir createNewDir(const QString &dirPath);

    QString path();
    void setPath(const QString &path);

// hide
private:
    QString name();
    void setName(const QString &name);
    int relationId();
    void setRelationId(int id);

};

class LostAndFound : public TDir
{
public:
    LostAndFound(QDomElement source);
    static QString tagName() { return "lost_and_found"; }

// hide
private:
    QString name();
    void setName(const QString &name);
    int relationId();
    void setRelationId(int id);
};


#endif // ENTRY_H
